<?
use WID\Test as Test;

return array(
	'name'=>'MockObject', 
	'desc'=>'Its testing MockObject class',
	
	'each'=> array(
		'mock'=>null
	),
	
	'beforeEach'=>function(&$each) {
		$each['mock'] = new Test\MockObject();
	}, 
	
	'tests'=>array(
		'creating'=>function(&$each) {
			$spy = $this->need->PropertiesSpy->onObject($each['mock']);
			
			//$this->expect($spy->valueOf('MockMethods'))->toBeArray();
			$this->expect($spy->valueOf('CurrentName'))->toBe('');
			$this->expect($spy->valueOf('CurrentArgs'))->toBe('[]');
		},
		
		'when'=>function(&$each) {
			$m = $each['mock'];
			$spy = $this->need->PropertiesSpy->onObject($m);
			
			$this->expect($m->when('test'))->toBe($m);
			$this->expect($spy->valueOf('CurrentName'))->toBe('test');
			
		},
		
		'getWithArgsAndNoMethodName'=>function(&$each) {
			$m = $each['mock'];
			$this->expect(function() use ($m) {
				$m->get(0,1);
			})->toThrow('WID\Test\MockObjectUndefinedMethodException')->withMessage('for args [0,1]');
			
		},
		
		'getWithArgs'=>function(&$each) {
			$m = $each['mock'];
			$spy = $this->need->PropertiesSpy->onObject($m);
			
			$this->expect($m->when('test')->get(0,1))->toBe($m);
			$this->expect($spy->valueOf('CurrentArgs'))->toBe('[0,1]');
			
		},
		
		'getWithArgs'=>function(&$each) {
			$m = $each['mock'];
			$spy = $this->need->PropertiesSpy->onObject($m);
			
			$this->expect($m->when('test')->get())->toBe($m);
			$this->expect($spy->valueOf('CurrentArgs'))->toBe('[]');
			
		},
		
		'giveWithNoMethodName'=>function(&$each) {
			$m = $each['mock'];
			
			$this->expect(function() use ($m) {
				$m->give(0);
			})->toThrow('WID\Test\MockObjectUndefinedMethodException')->withMessage("Can't set return value: 0");
		},
		
		'all'=>function(&$each) {
			$this->describe('tests full define mock method');
			$m = $each['mock'];
			$spy = $this->need->PropertiesSpy->onObject($m);
			
			$this->expect($m->when('test')->get(0,1)->give(1))->toBe($m);
			$this->expect($spy->valueOf('CurrentName'))->toBe('');
			$this->expect($spy->valueOf('CurrentArgs'))->toBe('[]');
			$methods = $spy->valueOf('Methods');
			$this->expect($methods['test']['[0,1]'])->toBe(1);
			
		},
	)
);
?>